package utilities;

import java.util.*;

public class TestStatSet implements Archiveable {
	Map<String, TestStat> stats;
	Map<String, TestStatSubclass> statSubclasses;
	
	public TestStatSet() {
		this.stats = new HashMap<String, TestStat>();
		this.stats.put("HP", new TestStat());
		this.stats.put("Mana", new TestStat());
		this.stats.put("Strength", new TestStat());
		
		this.statSubclasses = new HashMap<String, TestStatSubclass>();
		this.statSubclasses.put("Level", new TestStatSubclass("a base value"));
	}
	
	public Archive save() {
		Archive archive = new JSONArchive();
		
		archive.putPrimitiveToArchiveableMap("stats", this.stats);
		archive.putPrimitiveToArchiveableMap("statSubclasses", this.statSubclasses);
		
		return archive;
	}
	
	public void load(Archive archive) {
		Map<String, Archive> statMap = archive.getPrimitiveToArchiveableMap("stats");
		this.stats = new HashMap<String, TestStat>(statMap.keySet().size());
		for (String aKey : statMap.keySet()) {
			Archive value = statMap.get(aKey);
			TestStat stat = new TestStat();
			stat.load(value);
			this.stats.put(aKey, stat);
		}
		
		Map<String, Archive> statSubclassMap = archive.getPrimitiveToArchiveableMap("statSubclasses");
		this.statSubclasses = new HashMap<String, TestStatSubclass>(statSubclassMap.keySet().size());
		for (String aKey : statSubclassMap.keySet()) {
			Archive value = statSubclassMap.get(aKey);
			TestStatSubclass stat = new TestStatSubclass(null);
			stat.load(value);
			this.statSubclasses.put(aKey, stat);
		}
	}
	
}
